<?php
ALFileLoad::lib(ALViewController);

ALFileLoad::appfile("users/models.php");
ALFileLoad::appfile("users/forms.php");

class index extends ALViewController
{

	public function doGet($request)
	{

		$db = new ALDataObject('mytest','users');
		$users = $db
					->sortBy('-username, password')
					->limit(0)
					->offset(0)
					->oneToOne('user_mottos','user_id','mottos')
					->oneToOne('locations','id','loc','location_id')
					->filter('username LIKE \'%B%\'')
					->all();
					//->get();
		$users = $db->oneToOne('locations','id','loc','location_id')->joinFilter('id = 1')->all();

		foreach($users AS $user) {
			echo "{$user->username}: ";
			echo "{$user->loc->location}:{$user->loc->id}<br>";
		}

		/**
		 * Example add and update code
		 **/
		$user = new ALResultObject('mytest','users');
		$user->username = 'kyle';
		$user->password = 'straight';
		$user->save();
		
		$user->password = 'gay';
		$user->save();

		/**
		 * Example Delete A User
		 **/
		echo $user->delete()?'User deleted =]':'User delete failed ;[';

		return $request->view->render('sqlTransaction.php');

	}

}
